package com.ruoyi.web.controller.business;

import com.ruoyi.business.domain.TSmjMachineList;
import com.ruoyi.business.service.ITSmjGoodListService;
import com.ruoyi.business.service.ITSmjMachineListService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 售卖机信息Controller
 *
 * @author admin
 * @date 2024-10-24
 */
@Controller
@RequestMapping("/business/smjMachineList")
public class TSmjMachineListController extends BaseController
{
    private final Logger logger = LoggerFactory.getLogger(getClass());

    private String prefix = "business/smjMachineList";

    @Autowired
    private ITSmjMachineListService tSmjMachineListService;
    @Autowired
    private ITSmjGoodListService itSmjGoodListService;

    @RequiresPermissions("business:smjMachineList:view")
    @GetMapping()
    public String smjMachineList()
    {
        return prefix + "/smjMachineList";
    }

    /**
     * 查询售卖机信息列表
     */
    @RequiresPermissions("business:smjMachineList:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TSmjMachineList tSmjMachineList)
    {
        startPage();
        List<TSmjMachineList> list = tSmjMachineListService.selectTSmjMachineListList(tSmjMachineList);
        return getDataTable(list);
    }

    /**
     * 导出售卖机信息列表
     */
    @RequiresPermissions("business:smjMachineList:export")
    @Log(title = "售卖机信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TSmjMachineList tSmjMachineList)
    {
        List<TSmjMachineList> list = tSmjMachineListService.selectTSmjMachineListList(tSmjMachineList);
        ExcelUtil<TSmjMachineList> util = new ExcelUtil<TSmjMachineList>(TSmjMachineList.class);
        return util.exportExcel(list, "smjMachineList");
    }

    /**
     * 新增售卖机信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存售卖机信息
     */
    @RequiresPermissions("business:smjMachineList:add")
    @Log(title = "售卖机信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TSmjMachineList tSmjMachineList)
    {
        return toAjax(tSmjMachineListService.insertTSmjMachineList(tSmjMachineList));
    }

    /**
     * 修改售卖机信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TSmjMachineList tSmjMachineList = tSmjMachineListService.selectTSmjMachineListById(id);
        mmap.put("tSmjMachineList", tSmjMachineList);
        return prefix + "/edit";
    }

    /**
     * 修改保存售卖机信息
     */
    @RequiresPermissions("business:smjMachineList:edit")
    @Log(title = "售卖机信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TSmjMachineList tSmjMachineList)
    {
        return toAjax(tSmjMachineListService.updateTSmjMachineList(tSmjMachineList));
    }

    /**
     * 删除售卖机信息
     */
    @RequiresPermissions("business:smjMachineList:remove")
    @Log(title = "售卖机信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        //删除商品
        itSmjGoodListService.deleteTSmjGoodListByMachineIds(ids);
        return toAjax(tSmjMachineListService.deleteTSmjMachineListByIds(ids));
    }

    /**
     * 修改保存售卖机信息
     */
    @RequiresPermissions("business:smjMachineList:edit")
    @Log(title = "同步商品", businessType = BusinessType.UPDATE)
    @PostMapping("/anyscGoods")
    @ResponseBody
    public AjaxResult anyscGoods(TSmjMachineList tSmjMachineList)
    {
        return tSmjMachineListService.anyscGoods(tSmjMachineList);
    }

    @Log(title = "用户收款号状态变更", businessType = BusinessType.UPDATE)
    @RequiresPermissions("business:smjMachineList:edit")
    @PostMapping("/changeStatus")
    @ResponseBody
    public AjaxResult changeStatus(TSmjMachineList tSmjMachineList) {
        TSmjMachineList newtSmjMachineList = tSmjMachineListService.selectTSmjMachineListById(tSmjMachineList.getId());
        newtSmjMachineList.setMachineStatus(tSmjMachineList.getMachineStatus());
        return toAjax(tSmjMachineListService.updateTSmjMachineList(newtSmjMachineList));
//        return toAjax(tNginxInfoService.updateTNginxInfo(tNginxInfo));
    }
}
